public void colorizeModel(double[] hkt1, double[] hkt2)
{
	double[] values = new double[hkt1.GetLength(0)];
	double min = 1;
	double max = 0;
	double diff;
	for (int i = 0; i < hkt1.GetLength(0); i++)
	{
		diff = hkt1[i] - hkt2[i];
		min = Math.Min(min, diff);
		max = Math.Max(max, diff);
		values[i] = diff;
	}

	string offOutput = "colorized.off";
	Stream stream = File.Open(offOutput, FileMode.Create);
	StreamWriter sw = new StreamWriter(stream);

	TextReader reader = new StreamReader(fileName);

	//skip first line
	string line = reader.ReadLine();
	sw.WriteLine("[C]OFF");
	//second line contains vertices and faces counts.
	line = reader.ReadLine();
	sw.WriteLine(line);
	string[] split = line.Split(" ".ToCharArray());
	nrVertices = Convert.ToInt32(split[0]);

	//colorize all vertex descriptions
	int[] colors;
	for (int i = 0; i < nrVertices; i++)
	{
		colors = getColors(values[i], min, max);
		Console.WriteLine(values[i] + " " + colors[0] + " " + colors[1] + " " + colors[2]);
		sw.WriteLine(reader.ReadLine() + " " + colors[0] + " " + colors[1] + " " + colors[2]);
	}
	line = reader.ReadLine();
	sw.WriteLine(line);

	//write all face lines
	while (line != null)
	{
		line = reader.ReadLine();
		sw.WriteLine(line);
	}

	Console.WriteLine("min: " + min + " max: " + max);

	sw.Close();
	stream.Close();
	reader.Close();
}

public int[] getColors(double hktValue, double min, double max)
{
	int[] colors = new int[3];
	hktValue = (hktValue - min) / (max - min);
	hktValue = Math.Max(0, Math.Min(1, hktValue));
	
	// red
	colors[0] = (int)Math.Round(255 * Math.Max(0, (2 * (hktValue - 0.4))));
	// blue
	colors[2] = (int)Math.Round(255 * Math.Max(0, 1 - (1.6 * hktValue)));
	// green, the rest
	colors[1] = 255 - colors[0] - colors[2];

	//Console.WriteLine("R:" + colors[0] + " G:" + colors[1] + " B:" + colors[2]);

	return colors;
}